<?php
	//Trieu: dong nay can thiet cho viec add enviromment va cac bien
	require_once ( '../../../wp-blog-header.php');
?>

<?php
	//Tuy theo ket qua ma cau query khac nhau
	
	$tab = $_REQUEST['tablist'];
	switch ($tab){
		case '1':
			$query = "SELECT * FROM $wpdb->posts
       				WHERE post_status='publish'
					ORDER BY ID DESC
					LIMIT 0, 10";
			break;
		case '2':
			$query = "SELECT * FROM $wpdb->posts
       				WHERE post_status='publish'
					ORDER BY comment_count DESC, ID DESC
					LIMIT 0, 10";
			break;
		case '3':
			$query = "SELECT * FROM $wpdb->posts
       				WHERE post_status='publish' AND comment_count='0'
					ORDER BY ID DESC
					LIMIT 0, 10";
			break;
	}
?>

<div id='response'>		
		<?php 	
       		$results = $wpdb->get_results($query, OBJECT); //Trieu: lay ket qua 1 mang cac post id
       ?>	       
    	<div id="sc" class="tabcontainer">  <!-- #tabcontainer (Trieu)chua list -->
    	
    	<?php foreach ($results as $post):?>
    	 	<?php //Trieu: Doi voi moi post id, setup de query lay data 
    	 		
    	 		setup_postdata($post);
    	 		//the_post();
    	 	?>       
        	<div class="question"> <!-- #question (Trieu)item cua list danh sach-->
        		<div class="question-title">
            		<div class="question-user-img">
                		<img src="<?php bloginfo('template_directory');?>/images/question-img.jpg" />
                	</div>
                	<div class="question-by">
                		<p><?php the_author_posts_link();?></p>
                    	<p class="question-h1"><?php the_title();?></p>
                	</div>
                			<div style="clear:both;"></div>
            	</div>
				<div class="question-bottom">
					<div class="answer">
						<a href="<?php echo get_permalink();?>">Answer this question</a>
					</div>
					<div class="answers">
						<p> <!-- (Trieu) lay so comment, chia ra 3 truong hop 0, 1 va nhieu comment-->
							<?php comments_number( 
								'<font class="answer-nr">0 </font><a href="' . get_permalink() . '">Answer</a>',
								'<font class="answer-nr">1 </font><a href="' . get_permalink() . '">Answer</a>',
								'<font class="answer-nr">% </font><a href="' . get_permalink() . '">Answers</a>'
							);?>
						</p>
					</div>
					<div class="answer-date">
						<p> <?php the_time('F jS, Y');?> </p>
					</div>
					<div class="tags"> <!-- #tags (Trieu) cac tag lien quan den bai viet -->
						<?php $taglist = get_the_tag_list('<li>', '</li><li>,', '</li>');?>
						<?php if ($taglist != ''):?>
							<p>&laquo;&raquo;</p>
							<ul>
								<?php echo $taglist;?>
							</ul>
						<?php endif;?>
					</div> <!-- //tags -->
				</div>
			</div> <!-- //question -->
			<?php endforeach;?>
         </div> <!-- //tabcontainer -->
         
</div>
